/**
 * Created by Administrator on 2016/10/25 0025.
 */
    $(function(){
        $("#forgetM").on('click',function(){
            $(".find").show();
            $(".login").hide();
        });

        $("#registerN").on('click',function(){
            $(".register").show();
            $(".login").hide();
        });
         //登陆
        $("#loginIn").on('click',function(e){
            e.preventDefault();
            var Inputs = $(".login input");
            $.ajax({
                type:'POST',
                contentType: "application/x-www-form-urlencoded",
                dataType:'json',
                data:{
                    "username":Inputs.eq(0).val(),
                    "password": Inputs.eq(1).val()
                },
                url:window.U.url+'/users/token',
                success:function(result){
                    if(result.status=="1") {
                        sessionStorage.setItem("operatorObj",result.user_id);
                        window.location.href="reserveSituation.html";
                    }
                    else{
                        console.log(result.msg);
                    }
                },
                error:function(){
                    console.log("false");
                }
            });
        });

        $("#register").on('click',function(e){
            e.preventDefault();
            var Inputs = $(".register input");
            $.ajax({
                type:'POST',
                contentType: "application/x-www-form-urlencoded",
                dataType:'json',
                data:{
                    "username":Inputs.eq(0).val(),
                    "password": Inputs.eq(1).val(),
                    "phone":Inputs.eq(2).val(),
                    "email":Inputs.eq(3).val()
                },
                url:window.U.url+'/users',
                success:function(result){
                    if(result.status=="1") {
                        window.location.href="login.html";
                    }
                    else{
                        console.log(result.msg);
                    }
                },
                error:function(){
                    console.log("false");
                }
            });
        });
       /**
        $("#register").on('click',function(e){
            e.preventDefault();
            var Inputs = $(".find input");
            $.ajax({
                type:'POST',
                contentType: "application/x-www-form-urlencoded",
                dataType:'json',
                url:window.U.url+'/users/token',
                success:function(result){
                    if(result.status=="1") {
                        location.href="reserveSituation.html";
                    }
                    else{
                        console.log(result.msg);
                    }
                },
                error:function(){
                    console.log("false");
                }
            });
        })
       **/
    });
//倒计时发送
var countdown=60;
var mindown=0;
function settime(obj) {
    if (countdown <= mindown) {
        obj.removeAttribute("disabled");
        obj.value = "重新获取验证码";
        countdown = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value = "重新发送(" + countdown + ")";
        countdown--;
    }
    setTimeout(function() {
            settime(obj) }
        ,1000)
}

(function( $ ) {
    $.fn.togglePassword = function( options ) {
        var s = $.extend( $.fn.togglePassword.defaults, options ),
            input = $( this );

        $( s.el ).bind( s.ev, function() {
            "password" == $( input ).attr( "type" ) ?
                $( input ).attr( "type", "text" ) :
                $( input ).attr( "type", "password" );
        });
    };
    $.fn.togglePassword.defaults = {
        ev: "click"
    };
}( jQuery ));

$(function(){
    $('#password').togglePassword({
        el: '#togglePassword'
    });
})